// home 模块的小创库
//引入三级联动的接口
import {reqCategoryList,reqGetBannerList,reqGetFloorList} from "@/api";



//存放数据
const state = {
// state的初始值与服务器返回的一样 （服务器返回的数据是数组，则让categoryList为数组）
    categoryList:[],
    bannerList:[],
    floorList:[]
};
//mutations:修改state的唯一手段
const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList
    },
    GETBANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }
};
//action :书写自己的业务逻辑，也可以处理异步
const actions = {
    //async  await 同步存在，拿到成功返回结果
    async categoryList({commit}){
        const result = await reqCategoryList()
        if (result.code === 200){
            commit('CATEGORYLIST',result.data.slice(0,16))
            // console.log(result.data)
        }
    },
//    获取首页轮播图的数据
    async getBannerList({commit}){
      const result = await reqGetBannerList();
      if (result.code === 200){
          commit('GETBANNERLIST',result.data)
      }
    },
    async getFloorList({commit}){
       const result =  await reqGetFloorList();
       if (result.code === 200){
           commit('GETFLOORLIST',result.data)
       }


    }
};
//getters:理解为计算属性，用于简化创库数据，让组件获取创库的数据更方便
const getters = {

};
export default ({
    state,
    mutations,
    actions,
    getters
});